import { useUserStore } from '@/stores/user';

export function useHasPermi() {
  const userStore = useUserStore();

  function hasPermi(perms: string | string[]): boolean {
    const permissions: string[] = userStore.permissions || [];

    if (!perms) return false;

    if (typeof perms === 'string') {
      perms = [perms];
    }

    // 超级管理员权限
    if (permissions.includes('*:*:*')) return true;
    // 是否有任意一个权限
    return perms.some((perm) => permissions.includes(perm));
  }

  return hasPermi;
}
